package com.weiyin.examination.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathEffect;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.os.Build;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.Display;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;

import com.weiyin.examination.R;
import com.weiyin.examination.module.AnswerXml;
import com.weiyin.examination.module.BitMapModule;
import com.weiyin.examination.module.CourseDrawLineModule;
import com.weiyin.examination.module.MyRectF;
import com.weiyin.examination.module.Note;
import com.weiyin.examination.util.LogUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @author njf
 *         Created by lenovo on 2017/10/17.
 */

public class CourseView extends View {
    private static final String TAG = CourseView.class.getSimpleName();
    private static final int BUILD_SDK = 13;
    private Context mContext;
    static int anInt;
    /**
     * 获取图片压缩 这个的值压缩的倍数（2的整数倍），数值越小，压缩率越小，图片越清晰
     */
    private int inSampleSize = 0;
    private int deleter = 16;
    private Paint bufferPaint;
    private int height = 300;
    private int maxTop = 20;
    private int pdfBottom = 300;
    private int pdfSpacing = 19;
    private int lineWidth = 60;
    private int loadSize = 1;
    private int flatIndex = 0;
    private int courseA5X1 = 800;
    private int courseA5X2 = 900;
    private int courseA5X3 = 1150;
    private int courseA5X4 = 1400;
    private int courseA5Y1 = 70;
    private int courseA5Y2 = 450;

    private int note16Width = 15;


    public void setLoadSize(int loadSize) {
        this.loadSize = loadSize;
        pdfSpacing = getBitmapSize(note4HeadBitmap).bottom - 1;
    }

    public void setFlatIndex(int flatIndex) {
        this.flatIndex = flatIndex;
    }

    public void setHeight(int height) {
        LogUtil.i(TAG, "height=" + height);
        this.height = height - 193 - pdfSpacing;
        this.pdfBottom = height - 193 - pdfSpacing;
    }

    public void setPdfBottom(int pdfBottom1) {
        this.pdfBottom = pdfBottom - pdfBottom1;
        this.height = pdfBottom;
    }

    /**
     * 单个三连音时的宽
     */
    private static final int THREE_NOTES_WIDTH = 60;
    /**
     * 三连音的文字TOP
     */
    private static final int THREE_NOTES_TEXT_TOP = 20;
    /**
     * 三连音离音符的TOP
     */
    private static final int THREE_NOTES_TOP = 40;

    /**
     * 三连音其实top
     */
    private static final int THREE_NOTES_START_TOP = 10;
    private String type = "whole";

    private float lineX = 0;


    private int oldIndex = 0;

    /**
     * 初始化图片X坐标
     */
    private int bitmapX = 270;
    /**
     * 两个音符空隙（8分音符为基准）
     */
    private int pitchX = 30;

    public void setPitchX(int pitchX) {
        this.pitchX = pitchX;
    }

    /**
     * 装绘制出来的BitMapModule集合
     */
    private List<BitMapModule> bitMapModuleList;

    private List<AnswerXml> answerXmlList;
    /**
     * 连线BitMapModule集合
     */
    private List<BitMapModule> homoPhonicConnectionList;
    private BitMapModule closeBitmapModule;
    private Region closeRegion, closeA5Region;
    private RectF closeA5RectF;

    private GestureDetector mGestureDetector;

    private int mWidth;
    private int mHeight;
    private int index;

    /**
     * 是否第五题
     */
    private boolean courseA5 = false;

    /**
     * 几分音符为一拍
     */
    private int noteType = 0;
    /**
     * 是否需要连线
     */
    private boolean lineType = false;

    private int[] noteNumber = {60, 62, 64, 65, 67, 69, 71};
    private int[] noteNumberBottom = {60, 59, 57, 55, 54, 52, 50};


    private Bitmap oldBitmap;

    private Bitmap dropBitmap;
    private Bitmap heavyLiftBitmap;
    private Bitmap noteBitmap;
    private Bitmap note2Bitmap;
    private Bitmap note4Bitmap;
    private Bitmap note8Bitmap;
    private Bitmap note16Bitmap;
    private Bitmap noteDown8Bitmap;
    private Bitmap noteDown16Bitmap;
    private Bitmap noteDown4Bitmap;
    private Bitmap noteDown2Bitmap;
    private Bitmap reductionBitmap;
    private Bitmap reposeBitmap;
    private Bitmap repose2Bitmap;
    private Bitmap repose4Bitmap;
    private Bitmap repose8Bitmap;
    private Bitmap repose16Bitmap;
    private Bitmap riseBitmap;
    private Bitmap weightReductionBitmap;
    private Bitmap note4HeadBitmap;
    private Bitmap measureBitmap;
    private Bitmap trebleBitmap;
    private Bitmap bassBitmap;
    private Bitmap closeBitmap;
    private Bitmap closeNote16Bitmap;
    private Bitmap closeNote4Bitmap;
    private Bitmap closeNote8Bitmap;
    private List<Bitmap> bitmapList;

    private boolean isDraw = false;
    private boolean isRepose = false;
    private boolean spot = false;
    private boolean threeNote = false;
    private boolean homoPhonicConnection = false;
    private boolean closeNote = false;
    private boolean clef = true;
    private boolean terminate = true;
    private int mark = 0, homoPhonicConnectionIndex = 0;
    private boolean courseA2 = false;

    public List<AnswerXml> getAnswerXmlList() {
        return answerXmlList;
    }

    public void setCourseA2(boolean courseA2) {
        this.courseA2 = courseA2;
    }

    public boolean isTerminate() {
        return terminate;
    }

    public void setTerminate(boolean terminate) {
        this.terminate = terminate;
    }

    public void setCourseA5(boolean courseA5) {
        this.courseA5 = courseA5;
    }

    public void setNoteType(int noteType) {
        this.noteType = noteType;
    }

    public void setLineType(boolean lineType) {
        this.lineType = lineType;
    }

    public void setBitMapModuleList(List<BitMapModule> bitMapModuleList) {
        this.bitMapModuleList = bitMapModuleList;
    }

    public List<BitMapModule> getBitMapModuleList() {
        return bitMapModuleList;
    }

    public CourseView(Context context) {
        super(context);
        this.mContext = context;
        init();
    }

    public CourseView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        this.mContext = context;
        init();
    }

    public CourseView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.mContext = context;
        init();
    }

    public CourseView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        this.mContext = context;
        init();
    }

    @SuppressLint("ClickableViewAccessibility")
    private void init() {
        bitMapModuleList = new ArrayList<>();
        homoPhonicConnectionList = new ArrayList<>();
        answerXmlList = new ArrayList<>();

        bufferPaint = new Paint();
        bufferPaint.setAntiAlias(true);
        bufferPaint.setStyle(Paint.Style.STROKE);
        bufferPaint.setColor(Color.BLACK);
        bufferPaint.setTextSize(20);
        bufferPaint.setStrokeWidth((float) 1);
        mGestureDetector = new GestureDetector(new MyGestureDetector());
        this.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return mGestureDetector.onTouchEvent(event);
            }
        });
        initBitmap();

    }

    /**
     * 初始化图片
     */
    private void initBitmap() {
        BitmapFactory.Options opts = new BitmapFactory.Options();
        opts.inSampleSize = inSampleSize;

        dropBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.drop, opts);
        heavyLiftBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.heavy_lift, opts);
        noteBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.note, opts);
        note2Bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.note_2, opts);
        note4Bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.note_4, opts);
        note8Bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.note_8, opts);
        note16Bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.note_16, opts);
        noteDown8Bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.down_note_8, opts);
        noteDown16Bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.down_note_16, opts);
        noteDown4Bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.down_note_4, opts);
        noteDown2Bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.down_note_2, opts);
        reductionBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.reduction, opts);
        reposeBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.repose, opts);
        repose2Bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.repose_2, opts);
        repose4Bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.repose_4, opts);
        repose8Bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.repose_8, opts);
        repose16Bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.repose_16, opts);
        riseBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.rise, opts);
        weightReductionBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.weight_reduction, opts);
        note4HeadBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.note4_head, opts);
        measureBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.measure, opts);
        trebleBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.treble_clef, opts);
        bassBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.bass_clef, opts);
        closeBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.close_note, opts);
        closeNote16Bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.close_note16, opts);
        closeNote4Bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.close_note4, opts);
        closeNote8Bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.close_note2, opts);

        pdfSpacing = getBitmapSize(note4HeadBitmap).bottom;
        bitmapList = new ArrayList<>();
        bitmapList.add(riseBitmap);
        bitmapList.add(heavyLiftBitmap);
        bitmapList.add(reductionBitmap);
        bitmapList.add(dropBitmap);
        bitmapList.add(weightReductionBitmap);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);
        if (heightMode == MeasureSpec.EXACTLY) {
            mHeight = MeasureSpec.getSize(heightMeasureSpec);
            mWidth = MeasureSpec.getSize(widthMeasureSpec);
        } else {
            getScreenWidth();
        }
        setMeasuredDimension(mWidth, mHeight);
    }

    /**
     * 得到屏幕宽高
     */
    private void getScreenWidth() {
        WindowManager manager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();
        if (Build.VERSION.SDK_INT >= BUILD_SDK) {
            Point point = new Point();
            display.getSize(point);
            mWidth = point.x;
            mHeight = point.y;
        } else {
            mWidth = display.getWidth();
            mHeight = display.getHeight();
        }
    }

    private int noteIndex = 0;


    private void getDrawIndex(int noteNumber) {
        if (noteIndex < bitMapModuleList.size() - 1) {
            BitMapModule bitMapModule2 = bitMapModuleList.get(noteIndex + 1);
            int nType = bitMapModule2.getNoteType();
            if (!bitMapModule2.isMeasureLine()) {
                if (bitMapModule2.getRectF().left == bitMapModuleList.get(noteIndex).getRect().left || bitMapModule2.getRectF().right == bitMapModuleList.get(noteIndex).getRectF().right) {
                    if (bitMapModule2.isSpot() && !bitMapModule2.isRepose() && bitMapModule2.getNoteType() != 16) {
                        nType++;
                    }
                }
                if (!bitMapModule2.isThreeNotes()) {
                    if (nType != 0) {
                        if (nType + noteNumber <= noteType) {
                            noteIndex++;
                            getDrawIndex(bitMapModule2.getNoteType() + noteNumber);
                        }
                    }
                }
            }
        }
    }

    @Override
    protected void onDraw(Canvas canvas) {
        LogUtil.i(TAG, "onDraw");
        if (homoPhonicConnectionList != null) {
            homoPhonicConnectionList.clear();
        }
        bufferPaint.setStrokeWidth((float) 1.0);
        noteIndex = 0;
        homoPhonicConnectionIndex = 0;
        threeNotesIndex = 0;

        drawBackground(canvas);
        drawBitmap(canvas);
        deleteDraw(canvas);
        onDrawHome(canvas);


        if (courseA5) {
            drawCourseA5Background(canvas);
        }
    }

    private void drawBackground(Canvas canvas) {
        LogUtil.i(TAG, "drawBackground");
        for (int i = -2; i < 3; i++) {
            //绘制五线  pdfBottom 为中间第三线
            canvas.drawLine(0, pdfBottom + i * (pdfSpacing + 1), mWidth, pdfBottom + i * (pdfSpacing + 1), bufferPaint);
        }
        //绘制高低音谱号
        if (clef) {
            Rect rect = getBitmapSize(trebleBitmap);
            RectF rectF = new RectF();
            rectF.top = pdfBottom - rect.bottom / 2;
            rectF.left = 10;
            rectF.right = rectF.left + rect.right;
            rectF.bottom = rectF.top + rect.bottom;
            canvas.drawBitmap(trebleBitmap, rect, rectF, bufferPaint);
        } else {
            Rect rect = getBitmapSize(bassBitmap);
            RectF rectF = new RectF();
            rectF.top = pdfBottom - rect.bottom / 2;
            rectF.left = 10;
            rectF.right = rectF.left + rect.right;
            rectF.bottom = rectF.top + rect.bottom;
            canvas.drawBitmap(bassBitmap, rect, rectF, bufferPaint);
        }
        if (courseA2) {
            canvas.drawLine(mWidth / 2, pdfBottom - (pdfSpacing + 1) * 2, mWidth / 2, pdfBottom + (pdfSpacing + 1) * 2, bufferPaint);
        }

        if (terminate) {
            //绘制结尾两根线
            bufferPaint.setStrokeWidth((float) 3);
            canvas.drawLine(mWidth - 15, pdfBottom - (pdfSpacing + 1) * 2, mWidth - 15, pdfBottom + (pdfSpacing + 1) * 2, bufferPaint);

            bufferPaint.setStrokeWidth((float) 10);
            canvas.drawLine(mWidth - 5, pdfBottom - (pdfSpacing + 1) * 2, mWidth - 5, pdfBottom + (pdfSpacing + 1) * 2, bufferPaint);
            bufferPaint.setStrokeWidth((float) 1);
        } else {
            //绘制结尾两根线
            bufferPaint.setStrokeWidth((float) 3);
            canvas.drawLine(mWidth - 3, pdfBottom - (pdfSpacing + 1) * 2, mWidth - 3, pdfBottom + (pdfSpacing + 1) * 2, bufferPaint);
        }
    }

    private void drawCourseA5Background(Canvas canvas) {
        Paint paint = new Paint();

        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(Color.BLACK);
        Path path = new Path();

        path.moveTo(0, 10);
        path.addRect(new RectF(courseA5X1, courseA5Y1, courseA5X2, courseA5Y2), Path.Direction.CW);

        Path path1 = new Path();
        path1.moveTo(0, 10);
        path1.addRect(new RectF(courseA5X3, courseA5Y1, courseA5X4, courseA5Y2), Path.Direction.CW);
        PathEffect effects = new DashPathEffect(new float[]{5, 5, 5, 5}, 1);
        paint.setPathEffect(effects);
        canvas.drawPath(path, paint);
        canvas.drawPath(path1, paint);
    }

    private void drawBitmap(Canvas canvas) {
        LogUtil.i(TAG, "bitMapModuleList.size()=" + bitMapModuleList.size());
        for (int i = 0; i < bitMapModuleList.size(); i++) {
            BitMapModule bitMapModuleOld = bitMapModuleList.get(i);

            if (bitMapModuleOld.isSpot() && !bitMapModuleOld.isRepose() && bitMapModuleOld.getNoteType() != 16) {
                getDrawIndex(bitMapModuleOld.getNoteType() + 1);
            } else {
                getDrawIndex(bitMapModuleOld.getNoteType());
            }
            if (bitMapModuleOld.isThreeNotes()) {
                noteIndex = i + 2;
            }
            if (noteIndex >= bitMapModuleList.size()) {
                noteIndex = bitMapModuleList.size() - 1;
            }
            LogUtil.i(TAG, "noteIndex=" + noteIndex);
            Rect noteRect = getBitmapSize(note4HeadBitmap);
            if (lineType && i != bitMapModuleList.size() - 1 && bitMapModuleOld.isDrawLine() && bitMapModuleOld.getNoteType() < noteType && noteIndex != i) {
                List<BitMapModule> bitMapModules = new ArrayList<>();
                for (int j = i; j < noteIndex + 1; j++) {
                    bitMapModules.add(bitMapModuleList.get(j).clone());
                    if (bitMapModuleList.get(j).isRepose()) {
                        drawLegato(canvas, bitMapModules, bitMapModuleOld);
                        bitMapModules.clear();
                    } else {
                        if (j == noteIndex) {
                            drawLegato(canvas, bitMapModules, bitMapModuleOld);
                        }
                    }
//                    LogUtil.i(TAG, "bitMapModuleList.get(j).clone().getRectF().top=" + bitMapModuleList.get(j).clone().getRectF().top);
                }
                i = noteIndex;
            } else {
                addHomoPhonicConnection(bitMapModuleOld);
                drawMark(canvas, bitMapModuleOld);
                if (bitMapModuleOld.isMeasureLine()) {
                    bufferPaint.setStrokeWidth(3);
                    canvas.drawLine(bitMapModuleOld.getRectF().left, pdfBottom - pdfSpacing * 2, bitMapModuleOld.getRectF().left, pdfBottom + pdfSpacing * 2, bufferPaint);
                    bufferPaint.setStrokeWidth(1);
                } else {
//                if (bitMapModuleOld.isHomoPhonicConnection()) {
//                    if (i + 1 < bitMapModuleList.size()) {
//                        onDrawHomoPhonicConnection(canvas, !(bitMapModuleOld.getRectF().bottom - noteRect.bottom / 2 < height), bitMapModuleOld, bitMapModuleList.get(i + 1));
//                        drawOneBitmap(canvas, bitMapModuleList.get(i), noteRect);
//                        drawOneBitmap(canvas, bitMapModuleList.get(i + 1), noteRect);
//                        i += 1;
//                    } else {
//                        onDrawHomoPhonicConnection(canvas, !(bitMapModuleOld.getRectF().bottom - noteRect.bottom / 2 < height), bitMapModuleOld, null);
//                        drawOneBitmap(canvas, bitMapModuleOld, noteRect);
//                    }
//                }
                    if (bitMapModuleOld.isThreeNotes()) {
                        if (i + 2 < bitMapModuleList.size()) {
                            onDrawThreeNotes(canvas, !(bitMapModuleOld.getRectF().bottom - noteRect.bottom / 4 < height), bitMapModuleOld, bitMapModuleList.get(i + 2));
                            drawOneBitmap(canvas, bitMapModuleList.get(i), noteRect);
                            drawOneBitmap(canvas, bitMapModuleList.get(i + 1), noteRect);
                            drawOneBitmap(canvas, bitMapModuleList.get(i + 2), noteRect);
                            i += 2;
                        } else {
                            if (i + 1 < bitMapModuleList.size()) {
                                drawOneBitmap(canvas, bitMapModuleList.get(i + 1), noteRect);
                                i++;
                            }
                            drawOneBitmap(canvas, bitMapModuleOld, noteRect);
                            onDrawThreeNotes(canvas, !(bitMapModuleOld.getRectF().bottom - noteRect.bottom / 4 < height), bitMapModuleOld, null);
                        }
                    }
                    if (!bitMapModuleOld.isThreeNotes()) {
                        drawOneBitmap(canvas, bitMapModuleOld, noteRect);
                    }
                }
            }
            noteIndex++;
        }
    }

    private void drawLegato(Canvas canvas, List<BitMapModule> bitMapModules, BitMapModule bitMapModuleOld) {
        Rect noteRect = getBitmapSize(note4HeadBitmap);
        if (bitMapModules.size() == 1) {
            drawOneBitmap(canvas, bitMapModules.get(0), noteRect);

            addHomoPhonicConnection(bitMapModules.get(0));
        } else {
            if (bitMapModules.size() == 2 && bitMapModules.get(1).isRepose()) {
                drawOneBitmap(canvas, bitMapModules.get(0), noteRect);
                drawOneBitmap(canvas, bitMapModules.get(1), noteRect);

                addHomoPhonicConnection(bitMapModules.get(0));
                addHomoPhonicConnection(bitMapModules.get(1));
            } else {
                int bitmapTop = 0;
                int bitmapBottom = 0;
                for (int k = 0; k < bitMapModules.size(); k++) {
                    BitMapModule bitMapModule = bitMapModules.get(k);
                    if (bitMapModule.getRectF().bottom - pdfSpacing / 4 < height) {
                        bitmapTop++;
                    } else {
                        bitmapBottom++;
                    }
                }
                LogUtil.i(TAG, "bitmapTop=" + bitmapTop + " bitmapBottom=" + bitmapBottom);
                BitMapModule bitMapModuleMin = bitMapModules.get(0);
                BitMapModule bitMapModuleMax = bitMapModules.get(0);
                BitMapModule bitMapModuleTop = bitMapModules.get(0).clone();
                for (int j = 0; j < bitMapModules.size(); j++) {
                    if (bitMapModules.get(j).isRepose()) {
                        break;
                    }
                    if (bitMapModuleMin.getRectF().left > bitMapModules.get(j).getRectF().left) {
                        bitMapModuleMin = bitMapModules.get(j);
                    } else {
                        if (bitMapModuleMin.getRectF().left == bitMapModules.get(j).getRectF().left && bitMapModuleMin.getRectF().top < bitMapModules.get(j).getRectF().top) {
                            bitMapModuleMin = bitMapModules.get(j);
                        }
                    }
                    if (bitMapModuleMax.getRectF().left < bitMapModules.get(j).getRectF().left) {
                        bitMapModuleMax = bitMapModules.get(j);
                    } else {
                        if (bitMapModuleMax.getRectF().left == bitMapModules.get(j).getRectF().left && bitMapModuleMax.getRectF().top < bitMapModules.get(j).getRectF().top) {
                            bitMapModuleMax = bitMapModules.get(j);
                        }
                    }
                    if (bitmapTop > bitmapBottom) {
                        LogUtil.i(TAG, "bitMapModuleTop.getRectF().top=" + bitMapModuleTop.getRectF().top
                                + "bitMapModuleTop.getRectF().bottom=" + bitMapModuleTop.getRectF().bottom
                                + " bitMapModules.get(j).getRectF().bottom=" + bitMapModules.get(j).getRectF().bottom
                                + " bitMapModules.get(j).getRectF().top=" + bitMapModules.get(j).getRectF().top +
                                " bitMapModules.get(j).getRect().bottom=" + bitMapModules.get(j).getRect().bottom);
                        if (bitMapModuleTop.getRectF().top < bitMapModules.get(j).getRectF().bottom + bitMapModules.get(j).getRect().bottom) {
                            bitMapModuleTop.getRectF().top = bitMapModules.get(j).getRectF().bottom + bitMapModules.get(j).getRect().bottom;
                        }
                    } else {
                        if (bitMapModuleTop.getRectF().top > bitMapModules.get(j).getRectF().bottom - bitMapModules.get(j).getRect().bottom) {
                            bitMapModuleTop.getRectF().top = bitMapModules.get(j).getRectF().bottom - bitMapModules.get(j).getRect().bottom - maxTop;
                        }
                    }
                }
                bitMapModuleMax.getRectF().top = bitMapModuleTop.getRectF().top;
                float top = Math.abs(bitMapModuleMax.getRectF().top - bitMapModuleMin.getRectF().top);
//                LogUtil.i(TAG, "top=" + top);

                LogUtil.i(TAG, "bitMapModuleMin.getRectF().top=" + bitMapModuleMin.getRectF().top + " bitMapModuleMax.getRectF().top=" + bitMapModuleMax.getRectF().top);
                if (top > maxTop) {
                    if (bitmapTop > bitmapBottom) {
                        if (bitMapModuleMax.getRectF().top > bitMapModuleMin.getRectF().top) {
                            bitMapModuleMin.getRectF().top = bitMapModuleMax.getRectF().top - maxTop;
                        } else {
                            bitMapModuleMax.getRectF().top = bitMapModuleMin.getRectF().top - maxTop;
                        }
                    } else {
                        if (bitMapModuleMax.getRectF().top > bitMapModuleMin.getRectF().top) {
                            bitMapModuleMax.getRectF().top = bitMapModuleMin.getRectF().top + maxTop;
                        } else {
                            bitMapModuleMin.getRectF().top = bitMapModuleMax.getRectF().top + maxTop;
                        }
                    }
                }
                LogUtil.i(TAG, "bitMapModuleMin.getRectF().top=" + bitMapModuleMin.getRectF().top + " bitMapModuleMax.getRectF().top=" + bitMapModuleMax.getRectF().top + "bitMapModuleMin.getRectF().bottom=" + bitMapModuleMin.getRectF().bottom + " bitMapModuleMax.getRectF().bottom=" + bitMapModuleMax.getRectF().bottom);
                for (int j = 1; j < bitMapModules.size() - 1; j++) {
                    drawBitmap(bitMapModules.get(j), bitMapModuleMin, bitMapModuleMax);

                    addHomoPhonicConnection(bitMapModules.get(j));
                }
                addHomoPhonicConnection(bitMapModuleMin);
                addHomoPhonicConnection(bitMapModuleMax);
                if (bitmapTop > bitmapBottom) {
                    RectF rectF = bitMapModuleMin.getRectF();
                    RectF rectFNew = bitMapModuleMax.getRectF();
                    Rect rect = bitMapModuleMin.getRect();
                    Rect rectNew = bitMapModuleMax.getRect();
                    bufferPaint.setStrokeWidth((float) 8.0);
                    canvas.drawLine(rectF.left, rectF.bottom + rect.bottom,
                            rectFNew.left, rectFNew.top, bufferPaint);

                    float threeTop;
                    float x3 = 0;
                    if (bitMapModules.size() > 1) {
                        RectF rectF1 = bitMapModules.get(1).getRectF();
                        threeTop = rectF1.top + THREE_NOTES_TEXT_TOP;
                        x3 = rectF1.left - 5;
                        LogUtil.i(TAG, "threeTop=" + threeTop + " rectF1.top=" + rectF1.top);
                    } else {
                        threeTop = rectFNew.top;
                        x3 = rectFNew.left - 5;
                        LogUtil.i(TAG, "threeTop=" + threeTop + " rectFNew.top=" + rectFNew.top);
                    }
                    if (bitMapModuleOld.isThreeNotes()) {
                        bufferPaint.setStrokeWidth((float) 2);
                        canvas.drawText("3", x3, threeTop + THREE_NOTES_TEXT_TOP, bufferPaint);
                    }
                    bufferPaint.setStrokeWidth((float) 1.0);
                } else {
                    RectF rectF = bitMapModuleMin.getRectF();
                    RectF rectFNew = bitMapModuleMax.getRectF();
                    float threeTop;
                    int x3 = 0;
                    if (bitMapModules.size() > 1) {
                        RectF rectF1 = bitMapModules.get(1).getRectF();
                        x3 = (int) bitMapModules.get(1).getRectF().left + noteRect.right - 5;
                        threeTop = rectF1.top;
                    } else {
                        threeTop = rectF.top;
                        x3 = (int) bitMapModules.get(0).getRectF().left + noteRect.right - 5;
                    }
                    bufferPaint.setStrokeWidth((float) 8.0);
                    canvas.drawLine(rectF.right - (bitMapModuleMin.getRect().right - noteRect.right), rectF.top,
                            rectFNew.right - (bitMapModuleMax.getRect().right - noteRect.right), rectFNew.top, bufferPaint);
                    if (bitMapModuleOld.isThreeNotes()) {
                        bufferPaint.setStrokeWidth((float) 2);
                        canvas.drawText("3", x3, threeTop - THREE_NOTES_TEXT_TOP, bufferPaint);
                    }
                    bufferPaint.setStrokeWidth((float) 1.0);
                }
                for (int j = 0; j < bitMapModules.size(); j++) {
                    BitMapModule bitMapModule = bitMapModules.get(j);

                    drawMark(canvas, bitMapModule);
                    if (bitmapTop > bitmapBottom) {
                        if (j != 0 && bitMapModules.get(j - 1).getNoteType() == 1) {
                            drawBitmapLine(canvas, bitMapModule, bitMapModuleMin, bitMapModuleMax, bitMapModules.get(j - 1), false, true);
                        } else {
                            if (j == bitMapModules.size() - 1) {
                                drawBitmapLine(canvas, bitMapModule, bitMapModuleMin, bitMapModuleMax, bitMapModules.get(j - 1), true, true);
                            } else {
                                if (bitMapModules.get(j + 1).getNoteType() != 1) {
                                    drawBitmapLine(canvas, bitMapModule, bitMapModuleMin, bitMapModuleMax, bitMapModules.get(j + 1), false, true);
                                } else {
                                    drawBitmapLine(canvas, bitMapModule, bitMapModuleMin, bitMapModuleMax, bitMapModules.get(j + 1), false, false);
                                }
                            }
                        }
//                        if (j + 1 < bitMapModules.size()) {
//                            onDrawHomoPhonicConnection(canvas, false, bitMapModule, bitMapModules.get(j + 1));
//                        } else {
//                            if (bitMapModules.get(j).isHomoPhonicConnection()) {
//                                BitMapModule bitMapModule1 = null;
//                                if (noteIndex + 1 < bitMapModuleList.size()) {
//                                    bitMapModule1 = bitMapModuleList.get(noteIndex + 1);
//                                }
//                                onDrawHomoPhonicConnection(canvas, false, bitMapModule, bitMapModule1);
//                            }
//                        }
                    } else {
                        drawCircle(canvas, false, bitMapModule);
//                        if (j + 1 < bitMapModules.size()) {
//                            onDrawHomoPhonicConnection(canvas, true, bitMapModule, bitMapModules.get(j + 1));
//                        } else {
//                            if (bitMapModules.get(j).isHomoPhonicConnection()) {
//                                BitMapModule bitMapModule1 = null;
//                                if (noteIndex + 1 < bitMapModuleList.size()) {
//                                    bitMapModule1 = bitMapModuleList.get(noteIndex + 1);
//                                }
//                                onDrawHomoPhonicConnection(canvas, true, bitMapModule, bitMapModule1);
//                            }
//                        }
                        if (!bitMapModule.isRepose()) {
                            RectF rectF = new RectF();
                            rectF.top = bitMapModule.getRectF().bottom - noteRect.bottom;
                            rectF.left = bitMapModule.getRectF().left;
                            rectF.bottom = bitMapModule.getRectF().bottom;
                            rectF.right = rectF.left + noteRect.right;
                            canvas.drawBitmap(note4HeadBitmap, noteRect, rectF, bufferPaint);
                            canvas.drawLine(rectF.right, bitMapModule.getRectF().top, rectF.right, bitMapModule.getRectF().bottom - noteRect.bottom / 2, bufferPaint);

                            if (bitMapModule.getNoteType() == 1) {
                                if (j != 0 && bitMapModules.get(j - 1).getNoteType() == 1) {
                                    BitMapModule bitMapModule1 = bitMapModules.get(j - 1);
                                    int right = (int) bitMapModule1.getRectF().left;
                                    if (bitMapModule1.getNoteType() != 16) {
                                        right = right + noteRect.right;
                                    } else {
                                        right = right + bitMapModule1.getRect().right;
                                    }
                                    bufferPaint.setStrokeWidth((float) 8.0);
                                    canvas.drawLine(rectF.right, bitMapModule.getRectF().top + note16Width, right, bitMapModules.get(j - 1).getRectF().top + note16Width, bufferPaint);
                                    bufferPaint.setStrokeWidth((float) 1.0);
                                } else {
                                    if (j == bitMapModules.size() - 1) {
                                        bufferPaint.setStrokeWidth((float) 8.0);
                                        float bottom1 =
                                                getTop(rectF.right - note16Width, bitMapModuleMax, bitMapModuleMin);
                                        LogUtil.i(TAG, "bottom1=" + bottom1 + " bitMapModule.getRectF().top=" + bitMapModule.getRectF().top + " rectF.right=" + rectF.right + "bitMapModuleMax.gettop=" + bitMapModuleMax.getRectF().top);
                                        canvas.drawLine(rectF.right, bitMapModule.getRectF().top + note16Width, rectF.right - note16Width, bottom1 + note16Width, bufferPaint);
                                        bufferPaint.setStrokeWidth((float) 1.0);
                                    } else {
                                        if (bitMapModules.get(j + 1).getNoteType() != 1) {
                                            bufferPaint.setStrokeWidth((float) 8.0);
                                            float bottom1 =
                                                    getTop(rectF.right + note16Width, bitMapModuleMax, bitMapModuleMin);
                                            LogUtil.i(TAG, "bottom1=" + bottom1 + " bitMapModule.getRectF().top=" + bitMapModule.getRectF().top + " rectF.right=" + rectF.right);
                                            canvas.drawLine(rectF.right, bitMapModule.getRectF().top + note16Width, rectF.right + note16Width, bottom1 + note16Width, bufferPaint);
                                            bufferPaint.setStrokeWidth((float) 1.0);
                                        }
                                    }
                                }
                            }
                        } else {
                            canvas.drawBitmap(bitMapModule.getBitmap(), bitMapModule.getRect(), bitMapModule.getRectF(), bufferPaint);
                        }
                    }
                    drawLine(canvas, bitMapModule);
                }
            }
        }
    }

    private void drawOneBitmap(Canvas canvas, BitMapModule bitMapModuleOld, Rect noteRect) {
        if (bitMapModuleOld.getRectF().bottom - noteRect.bottom / 2 < height && bitMapModuleOld.isDrawLine()) {
            if (bitMapModuleOld.isRepose()) {
                canvas.drawBitmap(bitMapModuleOld.getBitmap(), bitMapModuleOld.getRect(), bitMapModuleOld.getRectF(), bufferPaint);
                drawLine(canvas, bitMapModuleOld);
            } else {
                drawCircle(canvas, true, bitMapModuleOld);
                Bitmap bitmap;
                if (bitMapModuleOld.getNoteType() == 2) {
                    bitmap = noteDown8Bitmap;
                    Rect rect = getBitmapSize(bitmap);
                    RectF rectF = new RectF();
                    rectF.top = bitMapModuleOld.getRectF().bottom - noteRect.bottom;
                    rectF.left = bitMapModuleOld.getRectF().left;
                    rectF.right = rectF.left + rect.right;
                    rectF.bottom = rectF.top + rect.bottom;
                    canvas.drawBitmap(bitmap, rect, rectF, bufferPaint);
                } else if (bitMapModuleOld.getNoteType() == 1) {
                    bitmap = noteDown16Bitmap;
                    Rect rect = getBitmapSize(bitmap);
                    RectF rectF = new RectF();
                    rectF.top = bitMapModuleOld.getRectF().bottom - noteRect.bottom;
                    rectF.left = bitMapModuleOld.getRectF().left;
                    rectF.right = rectF.left + rect.right;
                    rectF.bottom = rectF.top + rect.bottom;
                    canvas.drawBitmap(bitmap, rect, rectF, bufferPaint);
                } else if (bitMapModuleOld.getNoteType() == 4) {
                    bitmap = noteDown4Bitmap;
                    Rect rect = getBitmapSize(bitmap);
                    RectF rectF = new RectF();
                    rectF.top = bitMapModuleOld.getRectF().bottom - noteRect.bottom;
                    rectF.left = bitMapModuleOld.getRectF().left;
                    rectF.right = rectF.left + rect.right;
                    rectF.bottom = rectF.top + rect.bottom;
                    canvas.drawBitmap(bitmap, rect, rectF, bufferPaint);
                } else if (bitMapModuleOld.getNoteType() == 8) {
                    bitmap = noteDown2Bitmap;
                    Rect rect = getBitmapSize(bitmap);
                    RectF rectF = new RectF();
                    rectF.top = bitMapModuleOld.getRectF().bottom - noteRect.bottom;
                    rectF.left = bitMapModuleOld.getRectF().left;
                    rectF.right = rectF.left + rect.right;
                    rectF.bottom = rectF.top + rect.bottom;
                    canvas.drawBitmap(bitmap, rect, rectF, bufferPaint);
                } else {
                    if (courseA5) {
                        Rect rect = getBitmapSize(bitMapModuleOld.getBitmap());
                        RectF rectF = new RectF();
                        rectF.bottom = bitMapModuleOld.getRectF().bottom * loadSize / 2 - bitMapModuleOld.getRect().bottom * loadSize / 2 / 2 + rect.bottom / 2;
                        rectF.top = rectF.bottom - rect.bottom;
                        rectF.left = bitMapModuleOld.getRectF().left * loadSize / 2 - bitMapModuleOld.getRect().right * loadSize / 2 / 2 + rect.right / 2;
                        rectF.right = rectF.left + rect.right;
                        LogUtil.i(TAG, "rectF.bottom=" + rectF.bottom + " rectF.top=" + rectF.top + " rectF.left=" + rectF.left + " rectF.right=" + rectF.right + " rect.bottom=" + rect.bottom);
                        canvas.drawBitmap(bitMapModuleOld.getBitmap(), rect, rectF, bufferPaint);
                    } else {
                        canvas.drawBitmap(bitMapModuleOld.getBitmap(), bitMapModuleOld.getRect(), bitMapModuleOld.getRectF(), bufferPaint);
                    }
                }
                drawLine(canvas, bitMapModuleOld);
            }
        } else {
            drawCircle(canvas, false, bitMapModuleOld);
            if (courseA5) {
                Rect rect = getBitmapSize(bitMapModuleOld.getBitmap());
                RectF rectF = new RectF();
                rectF.bottom = bitMapModuleOld.getRectF().bottom * loadSize / 2 - bitMapModuleOld.getRect().bottom * loadSize / 2 / 2 + rect.bottom / 2;
                rectF.top = rectF.bottom - rect.bottom;
                rectF.left = bitMapModuleOld.getRectF().left * loadSize / 2 - bitMapModuleOld.getRect().right * loadSize / 2 / 2 + rect.right / 2;
                rectF.right = rectF.left + rect.right;
                LogUtil.i(TAG, "rectF.bottom=" + rectF.bottom + " rectF.top=" + rectF.top + " rectF.left=" + rectF.left + " rectF.right=" + rectF.right);
                canvas.drawBitmap(bitMapModuleOld.getBitmap(), rect, rectF, bufferPaint);
            } else {
                canvas.drawBitmap(bitMapModuleOld.getBitmap(), bitMapModuleOld.getRect(), bitMapModuleOld.getRectF(), bufferPaint);
            }
            drawLine(canvas, bitMapModuleOld);
        }
    }

    private int threeNotesIndex = 0;

    private void deleteDraw(Canvas canvas) {
        if (closeNote) {
            if (courseA5) {
                if (closeA5RectF != null) {
                    bufferPaint.setColor(Color.parseColor("#F5A623"));
                    Rect rect = getBitmapSize(closeBitmap);
                    rect.bottom = rect.bottom / loadSize;
                    rect.right = rect.right / loadSize;

                    RectF rectFClose = new RectF();
                    rectFClose.top = closeA5RectF.top - rect.bottom;
                    rectFClose.left = closeA5RectF.right;
                    rectFClose.right = rectFClose.left + rect.right;
                    rectFClose.bottom = rectFClose.top + rect.bottom;

                    canvas.drawRect(closeA5RectF.left, closeA5RectF.top, closeA5RectF.right, closeA5RectF.bottom, bufferPaint);
                    closeA5Region = new Region((int) rectFClose.left, (int) rectFClose.top, (int) rectFClose.right, (int) rectFClose.bottom);
                    canvas.drawBitmap(closeBitmap, rect, rectFClose, bufferPaint);
                    bufferPaint.setColor(Color.BLACK);
                }
            } else {
                if (closeBitmapModule != null) {
                    bufferPaint.setColor(Color.parseColor("#F5A623"));
                    Rect rect = getBitmapSize(closeBitmap);

                    RectF rectF = closeBitmapModule.getRectF();
                    RectF rectFClose = new RectF();
                    rectFClose.top = rectF.top;
                    rectFClose.left = rectF.right;
                    rectFClose.right = rectFClose.left + rect.right;
                    rectFClose.bottom = rectFClose.top + rect.bottom;

                    RectF rectF1 = new RectF();
                    rectF1.bottom = rectF.bottom;
                    rectF1.left = rectF.left;

                    if (closeBitmapModule.getNoteType() < 8) {
                        Rect rect1 = getBitmapSize(closeNote4Bitmap);
                        rectF1.right = rectF1.left + rect1.right;
                        rectF1.top = rectF1.bottom - rect1.bottom;
                        LogUtil.i(TAG, "closeBitmapModule.getNoteType() < 8" + " rectF1.top=" + rectF1.top + " rectF1.right=" + rectF1.right + " rectF1.left=" + rectF1.left + " rectF1.bottom=" + rectF1.bottom);
                        canvas.drawBitmap(closeNote4Bitmap, rect1, rectF1, bufferPaint);
                    } else {
                        if (closeBitmapModule.getNoteType() == 8) {
                            LogUtil.i(TAG, "closeBitmapModule.getNoteType() == 8");
                            Rect rect1 = getBitmapSize(closeNote8Bitmap);
                            rectF1.right = rectF1.left + rect1.right;
                            rectF1.top = rectF1.bottom - rect1.bottom;
                            canvas.drawBitmap(closeNote8Bitmap, rect1, rectF1, bufferPaint);
                        } else {
                            Rect rect1 = getBitmapSize(closeNote16Bitmap);
                            rectF1.right = rectF1.left + rect1.right;
                            rectF1.top = rectF1.bottom - rect1.bottom;
                            LogUtil.i(TAG, "closeBitmapModule.getNoteType() != 8");
                            canvas.drawBitmap(closeNote16Bitmap, closeBitmapModule.getRect(), rectF, bufferPaint);
                        }
                    }
                    closeRegion = new Region((int) rectFClose.left, (int) rectFClose.top, (int) rectFClose.right, (int) rectFClose.bottom);
                    canvas.drawBitmap(closeBitmap, rect, rectFClose, bufferPaint);
                    bufferPaint.setColor(Color.BLACK);
                }
            }
        }
    }

    private void onDrawHome(Canvas canvas) {
        for (int i = 0; i < homoPhonicConnectionList.size(); i++) {
            if (i % 2 == 1) {
                onDrawHomoPhonicConnection(canvas, !(homoPhonicConnectionList.get(i - 1).getRectF().bottom < pdfBottom),
                        homoPhonicConnectionList.get(i - 1), homoPhonicConnectionList.get(i));
            }
        }
        if (homoPhonicConnectionList.size() % 2 == 0) {
            homoPhonicConnection = false;
        }
    }

    private void addHomoPhonicConnection(BitMapModule bitMapModule) {
        if (bitMapModule.isHomoPhonicConnection()) {
            if (homoPhonicConnectionList != null) {
                homoPhonicConnectionList.add(bitMapModule);
            }
        }
    }

    /**
     * 绘制同音连线
     *
     * @param canvas          canvas
     * @param type            true:朝下 false:朝上
     * @param bitMapModuleOld bitmapModule 对象
     */
    private void onDrawHomoPhonicConnection(Canvas canvas, boolean type, BitMapModule bitMapModuleOld, BitMapModule bitMapModuleNew) {
        if (bitMapModuleOld.isHomoPhonicConnection() && !bitMapModuleOld.isMeasureLine() && !bitMapModuleOld.isRepose()) {
            if (courseViewListener != null) {
                courseViewListener.courseViewResult(3);
            }
            if (bitMapModuleNew != null) {
                LogUtil.i(TAG, "homoPhonicConnectionIndex %2 =0   =" + homoPhonicConnectionIndex);
                drawHomoPhonicConnection(canvas, type, bitMapModuleOld, bitMapModuleNew);
            } else {
                LogUtil.i(TAG, "homoPhonicConnectionIndex %2 !=0   =" + homoPhonicConnectionIndex);
                drawHomoPhonicConnection(canvas, type, bitMapModuleOld, null);
            }
        }
    }

    /**
     * @param canvas          canvas
     * @param type            true:向下绘制 false：向上绘制
     * @param bitMapModuleOld 当前bitmapModule对象
     * @param bitMapModuleNew 下一个bitmapModule对象
     */
    private void drawHomoPhonicConnection(Canvas canvas, boolean type, BitMapModule bitMapModuleOld, BitMapModule bitMapModuleNew) {
        Path mPath = new Path();
        mPath.reset();
        RectF rectFStart = bitMapModuleOld.getRectF();
        Rect rectStart = bitMapModuleOld.getRect();
        if (type) {
            //起点
            mPath.moveTo(rectFStart.left + pdfSpacing / 2,
                    rectFStart.bottom + pdfSpacing / 4);
            if (bitMapModuleNew != null) {
                RectF rectFEnd = bitMapModuleNew.getRectF();
                Rect rectEnd = bitMapModuleNew.getRect();
                mPath.cubicTo(rectFStart.left + pdfSpacing / 2,
                        rectFStart.bottom + pdfSpacing, rectFEnd.left + rectEnd.right / 2, rectFEnd.bottom + pdfSpacing,
                        rectFEnd.left + pdfSpacing / 2, rectFEnd.bottom + pdfSpacing / 4);
            } else {
                mPath.cubicTo(rectFStart.left + pdfSpacing / 2, rectFStart.bottom + pdfSpacing,
                        rectFStart.right + pdfSpacing / 2, rectFStart.bottom + pdfSpacing,
                        rectFStart.right + pdfSpacing / 2, rectFStart.bottom + pdfSpacing / 4);
            }
        } else {
            //起点
            mPath.moveTo(rectFStart.left + pdfSpacing / 2,
                    rectFStart.bottom - pdfSpacing - pdfSpacing / 4);
            if (bitMapModuleNew != null) {
                RectF rectFEnd = bitMapModuleNew.getRectF();
                Rect rectEnd = bitMapModuleNew.getRect();
                mPath.cubicTo(rectFStart.left + pdfSpacing / 2,
                        rectFStart.bottom - pdfSpacing * 2, rectFEnd.left + pdfSpacing / 2, rectFEnd.bottom - pdfSpacing * 2,
                        rectFEnd.left + pdfSpacing / 2, rectFEnd.bottom - pdfSpacing / 4 - pdfSpacing);
            } else {
                mPath.cubicTo(rectFStart.left + pdfSpacing / 2, rectFStart.bottom - pdfSpacing * 2,
                        rectFStart.right + pdfSpacing / 2, rectFStart.bottom - pdfSpacing * 2,
                        rectFStart.right + pdfSpacing / 2, rectFStart.bottom - pdfSpacing - pdfSpacing / 4);
            }
        }
        bufferPaint.setStrokeWidth(4);
        //画path
        canvas.drawPath(mPath, bufferPaint);
        bufferPaint.setStrokeWidth(1);
    }

    private void onDrawThreeNotes(Canvas canvas, boolean type, BitMapModule bitMapModuleOld, BitMapModule bitMapModuleNew) {
//        Constant.showTextToast(mContext, "type=" + type);
        if (bitMapModuleOld != null && bitMapModuleOld.isThreeNotes()) {
            if (courseViewListener != null) {
                courseViewListener.courseViewResult(2);
            }
            if (bitMapModuleNew != null) {
                LogUtil.i(TAG, "threeNotesIndex %2 =0   =" + threeNotesIndex);
                drawThreeNotes(canvas, type, bitMapModuleOld, bitMapModuleNew);
            } else {
                LogUtil.i(TAG, "threeNotesIndex %2 !=0   =" + threeNotesIndex);
                drawThreeNotes(canvas, type, bitMapModuleOld, null);
            }
        }
    }

    private void drawThreeNotes(Canvas canvas, boolean type, BitMapModule bitMapModule, BitMapModule bitMapModuleNew) {
        if (bitMapModule.isThreeNotes() && !bitMapModule.isRepose()) {
            RectF rectF = bitMapModule.getRectF();
            Rect rect = bitMapModule.getRect();
            if (type) {
                if (bitMapModuleNew != null) {
                    RectF rectFNew = bitMapModuleNew.getRectF();
                    canvas.drawLine(rectF.right, rectF.top - THREE_NOTES_START_TOP, rectF.right, rectF.top - THREE_NOTES_TOP, bufferPaint);
                    canvas.drawLine(rectF.right, rectF.top - THREE_NOTES_TOP, rectFNew.right, rectFNew.top - THREE_NOTES_TOP, bufferPaint);
                    bufferPaint.setStrokeWidth((float) 2);
                    if (rectF.top > rectFNew.top) {
                        canvas.drawText("3", rectF.right + (rectFNew.right - rectF.right) / 2, rectF.top - THREE_NOTES_TOP - THREE_NOTES_TEXT_TOP, bufferPaint);
                    } else {
                        canvas.drawText("3", rectF.right + (rectFNew.right - rectF.right) / 2, rectFNew.top - THREE_NOTES_TOP - THREE_NOTES_TEXT_TOP, bufferPaint);
                    }
                    bufferPaint.setStrokeWidth((float) 1.0);
                    canvas.drawLine(rectFNew.right, rectFNew.top - THREE_NOTES_TOP, rectFNew.right, rectFNew.top - THREE_NOTES_START_TOP, bufferPaint);
                } else {
                    canvas.drawLine(rectF.right, rectF.top - THREE_NOTES_START_TOP, rectF.right, rectF.top - THREE_NOTES_TOP, bufferPaint);
                    canvas.drawLine(rectF.right, rectF.top - THREE_NOTES_TOP, rectF.right + THREE_NOTES_WIDTH, rectF.top - THREE_NOTES_TOP, bufferPaint);
                    bufferPaint.setStrokeWidth((float) 2);
                    canvas.drawText("3", rectF.right + (rectF.right + THREE_NOTES_WIDTH - rectF.right) / 2, rectF.top - THREE_NOTES_TOP - THREE_NOTES_TEXT_TOP, bufferPaint);
                    bufferPaint.setStrokeWidth((float) 1.0);
                    canvas.drawLine(rectF.right + THREE_NOTES_WIDTH, rectF.top - THREE_NOTES_TOP, rectF.right + THREE_NOTES_WIDTH, rectF.top - THREE_NOTES_START_TOP, bufferPaint);
                }
            } else {
                if (bitMapModuleNew != null) {
                    Rect rectNew = bitMapModuleNew.getRect();
                    RectF rectFNew = bitMapModuleNew.getRectF();
                    canvas.drawLine(rectF.left, rectF.bottom + rect.bottom + THREE_NOTES_START_TOP, rectF.left, rectF.bottom + THREE_NOTES_TOP + rect.bottom, bufferPaint);
                    canvas.drawLine(rectF.left, rectF.bottom + THREE_NOTES_TOP + rect.bottom, rectFNew.left, rectFNew.bottom + THREE_NOTES_TOP + rectNew.bottom, bufferPaint);
                    bufferPaint.setStrokeWidth((float) 2);
                    if (rectF.bottom > rectFNew.bottom) {
                        canvas.drawText("3", rectF.left + (rectFNew.left - rectF.left) / 2, rectF.bottom + THREE_NOTES_TOP + THREE_NOTES_TEXT_TOP + rect.bottom, bufferPaint);
                    } else {
                        canvas.drawText("3", rectF.left + (rectFNew.left - rectF.left) / 2, rectFNew.bottom + THREE_NOTES_TOP + THREE_NOTES_TEXT_TOP + rectNew.bottom, bufferPaint);
                    }
                    bufferPaint.setStrokeWidth((float) 1.0);
                    canvas.drawLine(rectFNew.left, rectFNew.bottom + THREE_NOTES_TOP + rectNew.bottom, rectFNew.left, rectFNew.bottom + rectNew.bottom + THREE_NOTES_START_TOP, bufferPaint);
                } else {
                    canvas.drawLine(rectF.left, rectF.bottom + rect.bottom + THREE_NOTES_START_TOP, rectF.left, rectF.bottom + rect.bottom + THREE_NOTES_TOP, bufferPaint);
                    canvas.drawLine(rectF.left, rectF.bottom + THREE_NOTES_TOP + rect.bottom, rectF.left + THREE_NOTES_WIDTH, rectF.bottom + THREE_NOTES_TOP + rect.bottom, bufferPaint);
                    bufferPaint.setStrokeWidth((float) 2);
                    canvas.drawText("3", rectF.left + (rectF.left + THREE_NOTES_WIDTH - rectF.left) / 2, rectF.bottom + THREE_NOTES_TOP + THREE_NOTES_TEXT_TOP + rect.bottom, bufferPaint);
                    bufferPaint.setStrokeWidth((float) 1.0);
                    canvas.drawLine(rectF.left + THREE_NOTES_WIDTH, rectF.bottom + THREE_NOTES_TOP + rect.bottom, rectF.left + THREE_NOTES_WIDTH, rectF.bottom + rect.bottom + THREE_NOTES_START_TOP, bufferPaint);
                }
            }
        }
    }

    /**
     * @param canvas          canvas
     * @param type            true:left false:right
     * @param bitMapModuleOld bitMapModule对象
     */
    private void drawCircle(Canvas canvas, boolean type, BitMapModule bitMapModuleOld) {
        if (bitMapModuleOld.isSpot() && bitMapModuleOld.getNoteType() != 16) {
            bufferPaint.setStrokeWidth(4);
            Rect noteRect = getBitmapSize(note4HeadBitmap);
            float right;
            if (bitMapModuleOld.getNoteType() < 4) {
                right = bitMapModuleOld.getRectF().right;
            } else {
                right = bitMapModuleOld.getRectF().right + 15;
            }
            if (type) {
                canvas.drawCircle(right, bitMapModuleOld.getRectF().bottom - noteRect.bottom / 2, 2, bufferPaint);
            } else {
                canvas.drawCircle(right, bitMapModuleOld.getRectF().bottom - noteRect.bottom / 2, 2, bufferPaint);
            }
            bufferPaint.setStrokeWidth(1);
        }
    }

    private void drawMark(Canvas canvas, BitMapModule bitMapModuleOld) {
        if (bitMapModuleOld.getMark() != 0 && !bitMapModuleOld.isRepose() && bitMapModuleOld.isDrawLine()) {
            Bitmap bitmap = bitmapList.get(bitMapModuleOld.getMark() - 6);
            Rect rect = getBitmapSize(bitmap);
            RectF rectF = new RectF();
            if (courseA5) {
                if (bitMapModuleOld.getMark() == 6 || bitMapModuleOld.getMark() == 8) {
                    rectF.bottom = bitMapModuleOld.getRectF().bottom * loadSize / 2 - bitMapModuleOld.getRect().bottom * loadSize / 2 / 2 + rect.bottom / 2;
                } else if (bitMapModuleOld.getMark() == 7) {
                    rectF.bottom = bitMapModuleOld.getRectF().bottom * loadSize / 2 - bitMapModuleOld.getRect().bottom * loadSize / 2 / 2 + rect.bottom / 2 + 3;
                } else {
                    rectF.bottom = bitMapModuleOld.getRectF().bottom * loadSize / 2 - bitMapModuleOld.getRect().bottom * loadSize / 2 + rect.bottom / 2 + 3;
                }
                rectF.top = rectF.bottom - rect.bottom;
                rectF.left = bitMapModuleOld.getRectF().left * loadSize / 2 - bitMapModuleOld.getRect().right * loadSize / 2 / 2 + rect.right / 2 - rect.right - 10;
                rectF.right = rectF.left + rect.right;
                LogUtil.i(TAG, "rectF.bottom=" + rectF.bottom + " rectF.top=" + rectF.top + " rectF.left=" + rectF.left + " rectF.right=" + rectF.right + " rect.bottom=" + rect.bottom);
                canvas.drawBitmap(bitmap, rect, rectF, bufferPaint);

            } else {
                rectF.left = bitMapModuleOld.getRectF().left - rect.right - 10;
                rectF.right = bitMapModuleOld.getRectF().left - 10;
                if (bitMapModuleOld.getMark() == 6 || bitMapModuleOld.getMark() == 8) {
                    rectF.bottom = bitMapModuleOld.getRectF().bottom + rect.bottom / 3;
                } else {
                    rectF.bottom = bitMapModuleOld.getRectF().bottom + 3;
                }
                rectF.top = rectF.bottom - rect.bottom;

                canvas.drawBitmap(bitmap, rect, rectF, bufferPaint);
            }
        }
    }

    private void drawBitmap(BitMapModule bitMapModule, BitMapModule bitMapModuleMin, BitMapModule bitMapModuleMax) {
        if (!bitMapModuleMin.isRepose() && !bitMapModuleMax.isRepose() && !bitMapModule.isRepose()) {
            if (bitMapModuleMax.getRectF().top != bitMapModuleMin.getRectF().top
                    && bitMapModuleMax.getRectF().left != bitMapModuleMin.getRectF().left) {
                float k = (bitMapModuleMax.getRectF().top - bitMapModuleMin.getRectF().top) /
                        (bitMapModuleMax.getRectF().left - bitMapModuleMin.getRectF().left);
                float b = bitMapModuleMax.getRectF().top - (bitMapModuleMax.getRectF().left * k);
                bitMapModule.getRectF().top = bitMapModule.getRectF().left * k + b;
                bitMapModule.setUpdate(true);
            } else if (bitMapModuleMax.getRectF().top == bitMapModuleMin.getRectF().top) {
                bitMapModule.getRectF().top = bitMapModuleMax.getRectF().top;
                bitMapModule.setUpdate(true);
                LogUtil.i(TAG, "bitMapModule.getRectF().top=" + bitMapModule.getRectF().top + " bitMapModuleMax.getRectF().top=" + bitMapModuleMax.getRectF().top);
            }
        }
    }

    private float getTop(float left, BitMapModule bitMapModuleMax, BitMapModule bitMapModuleMin) {
        Rect rect = getBitmapSize(note4HeadBitmap);
        float top = 0f;
        float k = (bitMapModuleMax.getRectF().top - bitMapModuleMin.getRectF().top) /
                (bitMapModuleMax.getRectF().left + rect.right - (bitMapModuleMin.getRectF().left + rect.right));
        float b = bitMapModuleMax.getRectF().top - ((bitMapModuleMax.getRectF().left + rect.right) * k);
        top = left * k + b;
        return top;
    }

    private float getBottom(BitMapModule bitMapModuleMax, BitMapModule bitMapModuleMin, float left) {
        float bottom;
        RectF rectF = bitMapModuleMin.getRectF();
        Rect rect = bitMapModuleMin.getRect();
        float top = rectF.bottom + rect.bottom;
        if (bitMapModuleMax.getRectF().top != top && bitMapModuleMax.getRectF().left != bitMapModuleMin.getRectF().left) {
            float k1 = (bitMapModuleMax.getRectF().top - top) / (bitMapModuleMax.getRectF().left - bitMapModuleMin.getRectF().left);
            float b1 = bitMapModuleMax.getRectF().top - (bitMapModuleMax.getRectF().left * k1);
            bottom = left * k1 + b1;
        } else {
            bottom = top;
        }
        return bottom;
    }

    private void drawBitmapLine(Canvas canvas, BitMapModule bitMapModule, BitMapModule bitMapModuleMin,
                                BitMapModule bitMapModuleMax, BitMapModule bitMapModule1, boolean end, boolean isDrawLine) {
        if (!bitMapModule.isRepose()) {
            Rect rect = getBitmapSize(note4HeadBitmap);
            float bottom =
                    getBottom(bitMapModuleMax, bitMapModuleMin, bitMapModule.getRectF().left);
            RectF rectF = new RectF();
            rectF.bottom = bitMapModule.getRectF().bottom;
            rectF.left = bitMapModule.getRectF().left;
            rectF.right = rectF.left + rect.right;
            rectF.top = rectF.bottom - rect.bottom;
            drawCircle(canvas, true, bitMapModule);
//            float bottom = bitMapModule.getRectF().bottom + bitMapModule.getRectF().bottom - bitMapModule.getRectF().top;
            canvas.drawLine(bitMapModule.getRectF().left, bitMapModule.getRectF().bottom - rect.bottom / 2, bitMapModule.getRectF().left, bottom, bufferPaint);
            LogUtil.i(TAG, "bottom=" + bottom + " bitMapModule.getRectF().top=" + bitMapModule.getRectF().top + " bitMapModule.getRectF().bottom=" + bitMapModule.getRectF().bottom);
//            drawRotateBitmap(canvas, bufferPaint, note4HeadBitmap, 180, bitMapModule.getRectF().left, bitMapModule.getRectF().bottom);
            canvas.drawBitmap(note4HeadBitmap, rect, rectF, bufferPaint);
            bufferPaint.setStrokeWidth((float) 8.0);
            if (bitMapModule.getNoteType() == 1) {

                if (bitMapModule1.getNoteType() == 1) {
                    float bottom1 =
                            getBottom(bitMapModuleMax, bitMapModuleMin, bitMapModule1.getRectF().left);
                    LogUtil.i(TAG, " bitMapModule1.getRectF().top=" + bitMapModule1.getRectF().top + " bottom1=" + bottom1 + " bitMapModule.getRectF().bottom=" + bitMapModule1.getRectF().bottom);
//                    float bottom1 = bitMapModule1.getRectF().bottom - rect.bottom / 2 + bitMapModule1.getRectF().bottom - bitMapModule1.getRectF().top;

                    canvas.drawLine(bitMapModule.getRectF().left, bottom - note16Width, bitMapModule1.getRectF().left, bottom1 - note16Width, bufferPaint);
                } else {
                    if (end) {
                        float bottom1 =
                                getBottom(bitMapModuleMax, bitMapModuleMin, bitMapModule.getRectF().left - note16Width);
                        //bug
                        canvas.drawLine(bitMapModule.getRectF().left, bottom - note16Width, bitMapModule.getRectF().left - note16Width, bottom1 - note16Width, bufferPaint);
                    } else {
                        if (isDrawLine) {
                            float bottom1 =
                                    getBottom(bitMapModuleMax, bitMapModuleMin, bitMapModule.getRectF().left + note16Width);
                            canvas.drawLine(bitMapModule.getRectF().left, bottom - note16Width, bitMapModule.getRectF().left + note16Width, bottom1 - note16Width, bufferPaint);
                        }
                    }
                }
            }
            bufferPaint.setStrokeWidth((float) 1.0);
            drawLine(canvas, bitMapModule);
        } else {
            canvas.drawBitmap(bitMapModule.getBitmap(), bitMapModule.getRect(), bitMapModule.getRectF(), bufferPaint);
            drawLine(canvas, bitMapModule);
        }
    }

//    /**
//     * 绘制自旋转位图
//     *
//     * @param canvas
//     * @param paint
//     * @param bitmap   位图对象
//     * @param rotation 旋转度数
//     * @param posX     在canvas的位置坐标
//     * @param posY
//     */
//    private void drawRotateBitmap(Canvas canvas, Paint paint, Bitmap bitmap,
//                                  float rotation, float posX, float posY) {
//        Rect rect = getBitmapSize(note4HeadBitmap);
//        Matrix matrix = new Matrix();
//        int offsetX = bitmap.getWidth();
//        int offsetY = bitmap.getHeight();
//        matrix.postTranslate(-offsetX, -offsetY);
//        matrix.postRotate(rotation);
//        matrix.postTranslate(posX, posY - rect.bottom);
//        canvas.drawBitmap(bitmap, matrix, paint);
//    }


    /**
     * 获取bitmap的大小
     *
     * @param bmp bitmap
     */
    private Rect getBitmapSize(Bitmap bmp) {
        Rect rectF = new Rect();
        if (bmp != null) {
            rectF.left = 0;
            rectF.top = 0;
            rectF.right = (int) (bmp.getWidth() * loadSize);
            rectF.bottom = (int) (bmp.getHeight() * loadSize);
        } else {
            rectF.left = 0;
            rectF.top = 0;
            rectF.right = 0;
            rectF.bottom = 0;
        }
        return rectF;
    }

    /**
     * @param index                选择的为哪个音符
     * @param isDraw               是否绘制
     * @param isRepose             是否为休止符
     * @param spot                 是否为附点
     * @param mark                 升降号的下标
     * @param homoPhonicConnection 是否为同音连线
     * @param threeNote            是否为三连音
     * @param clef                 高低音谱号
     */
    public void setCurImg(int index, boolean isDraw, boolean isRepose,
                          boolean spot, int mark, boolean homoPhonicConnection,
                          boolean threeNote, boolean clef) {
        this.index = index;
        this.isDraw = isDraw;
        this.isRepose = isRepose;
        this.spot = spot;
        this.mark = mark;
        this.threeNote = threeNote;
        this.clef = clef;
        this.homoPhonicConnection = homoPhonicConnection;
        if (oldBitmap == null) {
            getBitmap(index);
        }

        if (index == deleter) {
            if (bitMapModuleList.size() > 0) {
//                if (bitMapModuleList.get(bitMapModuleList.size() - 1).getMark() != 0) {
//                    Bitmap bitmap = bitmapList.get(bitMapModuleList.get(bitMapModuleList.size() - 1).getMark() - 6);
//                    Rect markRect = getBitmapSize(bitmap);
//                    bitmapX = (int) (bitMapModuleList.get(bitMapModuleList.size() - 1).getRectF().left) + markRect.right + 10;
//                } else {
//                }
                BitMapModule bitMapModuleDeleter = bitMapModuleList.get(bitMapModuleList.size() - 1);
                if (bitMapModuleDeleter.isMeasureLine()) {
                    if (answerXmlList.size() > 0) {
                        answerXmlList.remove(answerXmlList.size() - 1);
                    }
                } else {
                    if (answerXmlList.size() > 0) {
                        List<Note> list = answerXmlList.get(answerXmlList.size() - 1).getNoteList();
                        if (list.size() > 0) {
                            list.remove(list.size() - 1);
                        }
                    }
                }
                bitMapModuleList.remove(bitMapModuleList.size() - 1);

                if (bitMapModuleList.size() > 0) {
                    BitMapModule b = bitMapModuleList.get(0);
                    bitmapX = (int) ((int) b.getRectF().left);
//                    bitmapX = (int) (bitMapModuleList.get(bitMapModuleList.size() - 1).getRectF().left);
                } else {
                    if (courseViewListener != null) {
                        courseViewListener.courseViewResult(4);
                    }
                }
                LogUtil.i(TAG, "deleter bitmapX=" + bitmapX);
                invalidate();
            } else {
                if (courseViewListener != null) {
                    courseViewListener.courseViewResult(4);
                }
            }

        }
    }

    private Bitmap getBitmap(int index) {
        LogUtil.i(TAG, index);
        Bitmap bitmap;
        switch (index) {
            case 0:
                if (clef) {
                    bitmap = trebleBitmap;
                } else {
                    bitmap = bassBitmap;
                }
                oldBitmap = bitmap;
                break;
            case 1:
                if (!isRepose) {
                    bitmap = noteBitmap;
                } else {
                    bitmap = reposeBitmap;
                }
                type = "whole";
                oldBitmap = bitmap;
                oldIndex = 16;
                break;
            case 2:
                if (!isRepose) {
                    bitmap = note2Bitmap;
                } else {
                    bitmap = repose2Bitmap;
                }
                type = "half";
                oldBitmap = bitmap;
                oldIndex = 8;
                break;
            case 3:
                if (!isRepose) {
                    bitmap = note4Bitmap;
                } else {
                    bitmap = repose4Bitmap;
                }
                type = "quarter";
                oldBitmap = bitmap;
                oldIndex = 4;
                break;
            case 4:
                if (!isRepose) {
                    bitmap = note8Bitmap;
                } else {
                    bitmap = repose8Bitmap;
                }
                type = "eighth";
                oldBitmap = bitmap;
                oldIndex = 2;
                break;
            case 5:
                if (!isRepose) {
                    bitmap = note16Bitmap;
                } else {
                    bitmap = repose16Bitmap;
                }
                type = "16th";
                oldBitmap = bitmap;
                oldIndex = 1;
                break;
            case 14:
                bitmap = measureBitmap;
                break;
            default:
                LogUtil.i(TAG, "default");
                bitmap = oldBitmap;
                break;
        }
        return bitmap;
    }

    int highLowPosition = 0;

    public void setHighLow(int position) {
        LogUtil.i(TAG, "highLowPosition=" + highLowPosition);
        this.highLowPosition = highLowPosition + position;
        if (highLowPosition < -21 || highLowPosition > 21) {
            this.highLowPosition = highLowPosition - position;
            position = 0;
        }
        if (bitMapModuleList.size() > 0) {
            BitMapModule bitMapModule = bitMapModuleList.get(bitMapModuleList.size() - 1);
            if (!bitMapModule.isRepose() && !bitMapModule.isMeasureLine()) {
                RectF rectF = bitMapModule.getRectF();

                rectF.bottom = rectF.bottom + position * pdfSpacing / 2;
                rectF.top = rectF.bottom - bitMapModule.getRect().bottom;

                bitMapModule.setRegion(new Region((int) rectF.left, (int) rectF.top, (int) rectF.right, (int) rectF.bottom));
                invalidate();
            }
        }
    }

    public void setBitmap(int bitmapIndex) {
        BitMapModule bitMapModule = new BitMapModule();
        Bitmap canvasBitmap = getBitmap(index);
        if (canvasBitmap == null) {
            return;
        }
        MyRectF rectF = new MyRectF();
        float position;
        switch (index) {
            case 1:
                position = 4;
                break;
            case 2:
                position = 3;
                break;
            case 3:
                position = 1.5f;
                break;
            case 4:
            case 14:
                position = 1;
                break;
            case 5:
                position = 0.5f;
                break;
            default:
                position = 0f;
                break;
        }
        Rect noteRect = getBitmapSize(note4HeadBitmap);

        Rect rect = getBitmapSize(canvasBitmap);

        if (bitMapModuleList.size() > 0) {
            for (int i = 0; i < bitMapModuleList.size(); i++) {
                RectF rectF1 = bitMapModuleList.get(i).getRectF();
                Region region;
                if (i < bitMapModuleList.size() - 1) {
                    if (bitMapModuleList.get(i + 1).getMark() != 0) {
                        Rect rect1 = getBitmapSize(bitmapList.get(bitMapModuleList.get(i + 1).getMark() - 6));
                        region = new Region((int) rectF1.left - rect1.right - 11, 0, (int) (rectF1.right + pitchX * bitMapModuleList.get(i + 1).getPosition()), 1000);
                    } else {
                        if (bitMapModuleList.get(i).getMark() != 0) {
                            Rect rect1 = getBitmapSize(bitmapList.get(bitMapModuleList.get(i).getMark() - 6));
                            region = new Region((int) rectF1.left - rect1.right - 11, 0, (int) (rectF1.right + pitchX * bitMapModuleList.get(i).getPosition()), 1000);
                        } else {
                            region = new Region((int) rectF1.left - 11, 0, (int) (rectF1.right + pitchX * bitMapModuleList.get(i).getPosition()), 1000);
                        }
                    }
                } else {
                    if (bitMapModuleList.get(i).getMark() != 0) {
                        Rect rect1 = getBitmapSize(bitmapList.get(bitMapModuleList.get(i).getMark() - 6));
                        region = new Region((int) rectF1.left - rect1.right - 11, 0, (int) (rectF1.right + pitchX * bitMapModuleList.get(i).getPosition()), 1000);
                    } else {
                        region = new Region((int) rectF1.left - 11, 0, (int) (rectF1.right + pitchX * bitMapModuleList.get(i).getPosition()), 1000);
                    }
                }
                if (region.contains(bitmapX, (int) (bitMapModuleList.get(i).getRectF().bottom - 5))) {
                    LogUtil.i(TAG, "bitmapX=" + bitmapX + " bitMapModuleList.get(i).getRectF().left=" + bitMapModuleList.get(i).getRectF().left);
                    if (mark != 0) {
                        Bitmap bitmap = bitmapList.get(mark - 6);
                        Rect markRect = getBitmapSize(bitmap);
                        bitmapX = (int) (bitMapModuleList.get(i).getRectF().left + bitMapModuleList.get(i).getRect().right + pitchX * (bitMapModuleList.get(i).getPosition())) + markRect.right + 10;
                    } else {
                        bitmapX = (int) (bitMapModuleList.get(i).getRectF().left + bitMapModuleList.get(i).getRect().right + pitchX * (bitMapModuleList.get(i).getPosition()));
                    }
                }
            }
            LogUtil.i(TAG, "bitmapX=" + bitmapX + " bitMapModuleList.get(size-1).getRectF().left=" + bitMapModuleList.get(bitMapModuleList.size() - 1).getRectF().left);
        } else {
            if (mark != 0) {
                Bitmap bitmap = bitmapList.get(mark - 6);
                Rect markRect = getBitmapSize(bitmap);
                bitmapX = (int) (200 + rect.right + pitchX * position) + markRect.right + 10;
            } else {
                bitmapX = (int) (200 + rect.right + pitchX * position);
            }
        }
        rectF.left = bitmapX;
        rectF.right = rectF.left + rect.right;
        if (!isRepose) {
            if (bitmapIndex == 14) {
                rectF.bottom = (pdfBottom + pdfSpacing * 2);
            } else {
                if (clef) {
                    rectF.bottom = (pdfBottom + pdfSpacing * 3) + pdfSpacing / 2 - (bitmapIndex - 1) * pdfSpacing / 2 + highLowPosition * pdfSpacing / 2;
                } else {
                    rectF.bottom = (pdfBottom - pdfSpacing * 3) - pdfSpacing / 2 + (bitmapIndex - 1) * pdfSpacing / 2 + highLowPosition * pdfSpacing / 2;
                }
            }
        } else {
            switch (index) {
                case 1:
                    rectF.bottom = pdfBottom - pdfSpacing / 2 + 1;
                    break;
                case 2:
                    rectF.bottom = pdfBottom + 1;
                    break;
                case 3:
                    rectF.bottom = (pdfBottom + pdfSpacing * 2) - pdfSpacing / 2;
                    break;
                case 4:
                    rectF.bottom = (pdfBottom + pdfSpacing * 2) - pdfSpacing;
                    break;
                case 5:
                    rectF.bottom = (pdfBottom + pdfSpacing * 2);
                    break;
                default:
                    break;
            }
        }
//        LogUtil.i(TAG, "rectF.bottom=" + rectF.bottom);
//        LogUtil.i(TAG, "rectF.bottom=" + rectF.bottom);
        rectF.top = rectF.bottom - rect.bottom;
//        LogUtil.i(TAG, " bitmapX==" + rectF.left);
        bitMapModule.setPosition(position);
        setBitmap(bitMapModule, rectF, rect, canvasBitmap, noteRect);
        if (courseViewListener != null) {
            courseViewListener.courseViewResult(1);
        }
    }

    private void setBitmap(BitMapModule bitMapModule, MyRectF rectF, Rect rect, Bitmap canvasBitmap, Rect noteRect) {
        switch (index) {
            case 0:
                bitMapModule.setNoteType(16);
                bitMapModule.setDrawLine(false);
                bitMapModule.setMeasureLine(false);
                break;
            case 1:
                bitMapModule.setNoteType(16);
                bitMapModule.setDrawLine(true);
                bitMapModule.setMeasureLine(false);
                oldIndex = 16;
                break;
            case 2:
                bitMapModule.setNoteType(8);
                bitMapModule.setDrawLine(true);
                oldIndex = 8;
                bitMapModule.setMeasureLine(false);
                break;
            case 3:
                bitMapModule.setNoteType(4);
                bitMapModule.setDrawLine(true);
                bitMapModule.setMeasureLine(false);
                oldIndex = 4;
                break;
            case 4:
                bitMapModule.setNoteType(2);
                bitMapModule.setDrawLine(true);
                bitMapModule.setMeasureLine(false);
                oldIndex = 2;
                break;
            case 5:
                bitMapModule.setNoteType(1);
                bitMapModule.setDrawLine(true);
                bitMapModule.setMeasureLine(false);
                oldIndex = 1;
                break;
            case 14:
                bitMapModule.setNoteType(16);
                bitMapModule.setDrawLine(false);
                bitMapModule.setMeasureLine(true);
                break;
            default:
                bitMapModule.setNoteType(oldIndex);
                bitMapModule.setDrawLine(true);
                bitMapModule.setMeasureLine(false);
                break;
        }
        if (bitMapModule.getNoteType() == 16) {
            bitMapModule.setThreeNotes(false);
        } else {
            bitMapModule.setThreeNotes(threeNote);
        }
        bitMapModule.setHomoPhonicConnection(homoPhonicConnection);
        bitMapModule.setMark(mark);
        bitMapModule.setSpot(spot);
        bitMapModule.setUpdate(false);
        bitMapModule.setBitmap(canvasBitmap);
        bitMapModule.setRect(rect);
        bitMapModule.setRectF(rectF);
        bitMapModule.setRepose(isRepose);
        bitMapModule.setClef(clef);
        returnPitch(bitMapModule, rectF, noteRect);
        Region region;
        if (!courseA5) {
            region = new Region((int) rectF.left, (int) rectF.top - 50, (int) rectF.right, (int) rectF.bottom + 50);
        } else {
            region = new Region((int) rectF.left, (int) rectF.top, (int) rectF.right, (int) rectF.bottom);
        }
        bitMapModule.setRegion(region);
//        LogUtil.i(TAG, "rectF.top=" + rectF.top + " rectF.bottom=" + rectF.bottom + " rectF.left=" + rectF.left + " rectF.right=" + rectF.right);
        if (!bitMapModule.isMeasureLine()) {
            addLine((int) rectF.bottom, bitMapModule);
        }
        if (answerXmlList.size() == 0) {
            answerXmlList.add(new AnswerXml());
        }
        if (bitMapModule.isMeasureLine()) {
            answerXmlList.add(new AnswerXml());
        }

        AnswerXml answerXml = answerXmlList.get(answerXmlList.size() - 1);
        if (answerXml.getNoteList() == null || answerXml.getNoteList().size() == 0) {
            answerXml.setNoteList(new ArrayList<Note>());
        }
        List<Note> noteList = answerXml.getNoteList();
        Note note = new Note();
        note.setDot(String.valueOf(spot));
        note.setRest(String.valueOf(isRepose));
        note.setActualNotes(String.valueOf(threeNote));
        note.setNormalNotes(String.valueOf(threeNote));
        note.setNormalType(type);
        note.setPitch(bitMapModule.getPitch() + "");
        note.setTied(String.valueOf(homoPhonicConnection));
        note.setType(type);
        note.setBitMapModule(bitMapModule);
        noteList.add(note);
        bitMapModuleList.add(bitMapModule);

        invalidate();
        mark = 0;
    }

    private void sortList() {
        if (bitMapModuleList != null) {

        }
    }

    private class MyGestureDetector implements GestureDetector.OnGestureListener {
        @Override
        public boolean onDown(MotionEvent e) {
            lineX = e.getX();
            if (courseViewListener != null) {
                courseViewListener.courseViewResult(1);
            }
            if (homoPhonicConnection) {
                boolean update = false;
                for (int i = 0; i < bitMapModuleList.size(); i++) {
                    BitMapModule bitMapModule = bitMapModuleList.get(i);
                    if (bitMapModule.getRegion().contains((int) e.getX(), (int) e.getY())) {
                        bitMapModule.setHomoPhonicConnection(!bitMapModule.isHomoPhonicConnection());
                        update = true;
                    }
                }
                if (update) {
                    invalidate();
                }
            } else {
                if (isDraw) {
                    float x = e.getX();
                    float y = e.getY();

                    Bitmap canvasBitmap = getBitmap(index);
//                LogUtil.i(TAG, "x=" + x + " y=" + y);
                    if (canvasBitmap == null || !(courseA5 && ((x > courseA5X3 && x < courseA5X4) || (x > courseA5X1 && x < courseA5X2) || (y < courseA5Y1) || (y > courseA5Y2)))) {
                        return false;
                    }

                    BitMapModule bitMapModule = new BitMapModule();
                    Rect rect = getBitmapSize(canvasBitmap);
                    MyRectF rectF = new MyRectF();
                    rectF.top = y - rect.bottom;
                    rectF.left = x - rect.right / 2;
                    rectF.bottom = rectF.top + rect.bottom;
                    rectF.right = rectF.left + rect.right;
                    Rect noteRect = getBitmapSize(note4HeadBitmap);
                    for (int i = 0; i < bitMapModuleList.size(); i++) {
                        BitMapModule bitMapModule1 = bitMapModuleList.get(i);
                        RectF rectF1 = bitMapModule1.getRectF();
                        boolean top = (rectF1.bottom - noteRect.bottom / 4 * 6) <= (rectF.bottom - noteRect.bottom);
                        boolean bottom = (rectF1.bottom + noteRect.bottom / 3) >= rectF.bottom;
                        boolean left = ((rectF1.left <= rectF.right && rectF1.left >= rectF.left)
                                || (rectF1.right >= rectF.left && rectF1.right <= rectF.right));

                        boolean result = top && bottom && left;
                        if (result) {
//                        LogUtil.i(TAG, " left=" + rectF.left + " right=" + rectF.right);
                            rectF.left = rectF1.right + 5;
                            rectF.right = rectF.left + rect.right;
                            rectF.bottom = rectF1.bottom;
                            rectF.top = rectF1.top;
//                        LogUtil.i(TAG, " left=" + rectF.left + " right=" + rectF.right);
                        }
                        if ((rectF1.left < rectF.right && rectF1.left > rectF.left)) {
                            rectF.left = rectF1.left;
                            rectF.right = rectF1.right;
                        }
                        if (rectF1.right > rectF.left && rectF1.right < rectF.right) {
                            rectF.left = rectF1.left;
                            rectF.right = rectF1.right;
                        }
                    }
                    if (courseA5) {
//                    LogUtil.i(TAG, "courseA5  rectF.right=" + rectF.right + "  rectF.left =" + rectF.left);
                        if (!(rectF.left > courseA5X1 && rectF.right < courseA5X2) && !(rectF.left > courseA5X3 && rectF.right < courseA5X4) || rectF.top < courseA5Y1 || rectF.bottom > courseA5Y2) {
                            return false;
                        }
                    }
                    setBitmap(bitMapModule, rectF, rect, canvasBitmap, noteRect);

                } else {
                    boolean update = false;
                    if (closeBitmapModule != null && closeRegion != null) {
                        if (closeRegion.contains((int) e.getX(), (int) e.getY()) && bitMapModuleList != null && bitMapModuleList.contains(closeBitmapModule)) {
                            LogUtil.i(TAG, "index=" + bitMapModuleList.indexOf(closeBitmapModule));
                            BitMapModule b = bitMapModuleList.get(0);
                            bitmapX = (int) ((int) b.getRectF().left);
                            //                        bitmapX = (int) (bitMapModuleList.get(bitMapModuleList.size() - 1).getRectF().left +
                            //                                pitchX * bitMapModuleList.get(bitMapModuleList.size() - 1).getPosition());
                            bitMapModuleList.remove(closeBitmapModule);
                            List<Note> notes = answerXmlList.get(0).getNoteList();
                            for (int j = 0; j < notes.size(); j++) {
                                if (notes.get(j).getBitMapModule() == closeBitmapModule) {
                                    notes.remove(j);
                                    j--;
                                }
                            }
                        }
                        closeNote = false;
                        update = true;
                        closeBitmapModule = null;
                    }
                    if (closeA5Region != null && bitMapModuleList != null) {
                        if (closeA5Region.contains((int) e.getX(), (int) e.getY())) {
                            Region region = new Region((int) closeA5RectF.left, (int) closeA5RectF.top, (int) closeA5RectF.right, (int) closeA5RectF.bottom);
                            for (int i = 0; i < bitMapModuleList.size(); i++) {
                                BitMapModule bitMapModule = bitMapModuleList.get(i);
                                if (region.contains((int) bitMapModule.getRectF().left + bitMapModule.getRect().right / 2,
                                        (int) bitMapModule.getRectF().bottom - bitMapModule.getRect().bottom / 2)) {
                                    List<Note> notes = answerXmlList.get(0).getNoteList();
                                    for (int j = 0; j < notes.size(); j++) {
                                        if (notes.get(j).getBitMapModule() == bitMapModule) {
                                            notes.remove(j);
                                            j--;
                                        }
                                    }
                                    bitMapModuleList.remove(bitMapModule);
                                    i--;
                                }
                            }
                        }
                        closeNote = false;
                        update = true;
                    }
                    if (courseA5) {
                        if ((lineX > courseA5X3 && lineX < courseA5X4)) {
                            closeA5RectF = new RectF();
                            closeA5RectF.top = courseA5Y1;
                            closeA5RectF.bottom = courseA5Y2;
                            closeA5RectF.left = courseA5X3;
                            closeA5RectF.right = courseA5X4;
                            update = true;
                            closeNote = true;
                        } else if (lineX > courseA5X1 && lineX < courseA5X2) {
                            closeA5RectF = new RectF();
                            closeA5RectF.top = courseA5Y1;
                            closeA5RectF.bottom = courseA5Y2;
                            closeA5RectF.left = courseA5X1;
                            closeA5RectF.right = courseA5X2;
                            update = true;
                            closeNote = true;
                        }
                    } else {
                        if (bitMapModuleList != null) {
                            for (int i = 0; i < bitMapModuleList.size(); i++) {
                                BitMapModule bitMapModule = bitMapModuleList.get(i);
                                if (bitMapModule.getRegion().contains((int) e.getX(), (int) e.getY())) {
                                    update = true;
                                    closeNote = true;
                                    closeBitmapModule = bitMapModule;
                                }
                            }
                        }
                    }
                    if (update) {
                        invalidate();
                    }
                }
            }

            return true;
        }

        @Override
        public void onShowPress(MotionEvent e) {
        }

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            return false;
        }

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            if (isDraw) {
                if (bitMapModuleList.size() > 0) {
                    addLine((int) e2.getY(), bitMapModuleList.get(bitMapModuleList.size() - 1));
                }
            }
            return false;
        }

        @Override
        public void onLongPress(MotionEvent e) {
            LogUtil.i(TAG, "onLongPress");
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            if (!isDraw) {
                LogUtil.i(TAG, "e1.getX()=" + e1.getX() + " e2.getX()=" + e2.getX());
                if (e1.getX() - e2.getX() > 120) {
                    if (courseViewListener != null) {
                        courseViewListener.courseViewResult(-2);
                    } else {
                        LogUtil.i(TAG, "courseViewListener==null");
                    }
                    return true;
                } else if (e1.getX() - e2.getX() < -120) {
                    if (courseViewListener != null) {
                        courseViewListener.courseViewResult(-1);
                    } else {
                        LogUtil.i(TAG, "courseViewListener==null");
                    }
                    return true;
                }
            }
            return false;
        }
    }

    private void returnPitch(BitMapModule bitMapModule, RectF rectF, Rect noteRect) {
        if (!bitMapModule.isRepose() && !bitMapModule.isMeasureLine()) {
            if (bitMapModule.isClef()) {
                int index = (int) ((pdfBottom + pdfSpacing * 3) - (rectF.bottom - pdfSpacing / 2)) / (pdfSpacing / 2);
//                LogUtil.i(TAG, "isClef = true index=" + index + " pdfBottom=" + pdfBottom + " pdfSpacing=" + pdfSpacing + " rectF.bottom=" + rectF.bottom);
                int i = index % 7;
                int position = index / 7;
                if (i < 0) {
                    i = 7 + i;
                }
                if (index < 0 && i != 0) {
                    position = position - 1;
                }

                int number = noteNumber[i];
                number = getNumber(bitMapModule, number);
                if (bitMapModule.getMark() == 6) {
                    number++;
                }
                if (bitMapModule.getMark() == 9) {
                    number--;
                }
                if (bitMapModule.getMark() == 10) {
                    number -= 2;
                }
                int pitch = (position * 12) + number;
//                LogUtil.i(TAG, "pitch = " + pitch + "i=" + i + " (position * 12)=" + (position * 12) + "   " + (index / 7));
                bitMapModule.setPitch(pitch);
//                Constant.showTextToast(mContext, "音高=" + pitch);
            } else {
                int index = (int) ((rectF.bottom - pdfSpacing / 2) - (pdfBottom - pdfSpacing * 3)) / (pdfSpacing / 2);
                int i = index % 7;
//                LogUtil.i(TAG, "isClef = false index=" + index + " pdfBottom=" + pdfBottom + " pdfSpacing=" + pdfSpacing + " rectF.bottom=" + rectF.bottom + " i=" + i);
                int position = index / 7;
                if (i < 0) {
                    i = 7 + i;
                }
                if (index < 0 && i != 0) {
                    position = position - 1;
                }
                int number = noteNumberBottom[i];
                number = getNumber(bitMapModule, number);
                if (bitMapModule.getMark() == 6) {
                    number++;
                }
                if (bitMapModule.getMark() == 9) {
                    number--;
                }
                if (bitMapModule.getMark() == 10) {
                    number -= 2;
                }
                int pitch = number - (position * 12);
//                LogUtil.i(TAG, "pitch = " + pitch + "i=" + i + " (position * 12)=" + (position * 12) + "   " + (index / 7));
                bitMapModule.setPitch(pitch);
//                Constant.showTextToast(mContext, "音高=" + pitch);
            }
        }
    }

    private int getNumber(BitMapModule bitMapModule, int number) {
        switch (flatIndex) {
            //                5 0 7 2 9 4 1    1 4 9 2 7 0 5
            case 0:
                if (bitMapModule.getMark() != 8 && number % 12 == 1) {
                    number--;
                }
                break;
            case 1:
                if (bitMapModule.getMark() != 8 && number % 12 != 5 && number % 12 != 0 && number % 12 != 7 && number % 12 != 2 && number % 12 != 9) {
                    number--;
                }
                break;
            case 2:
                if (bitMapModule.getMark() != 8 && number % 12 != 5 && number % 12 != 0 && number % 12 != 7 && number % 12 != 2) {
                    number--;
                }
                break;
            case 3:
                if (bitMapModule.getMark() != 8 && number % 12 != 5 && number % 12 != 0 && number % 12 != 7) {
                    number--;
                }
                break;
            case 4:
                if (bitMapModule.getMark() != 8 && number % 12 != 5 && number % 12 != 0) {
                    number--;
                }
                break;

            case 5:
                if (bitMapModule.getMark() != 8 && number % 12 != 5) {
                    number--;
                }
                break;
            case 6:
                if (bitMapModule.getMark() != 8) {
                    number--;
                }
                break;
            case 7:
                if (bitMapModule.getMark() != 8 && number % 12 == 5) {
                    number++;
                }
                break;
            case 8:
                if (bitMapModule.getMark() != 8 && number % 12 != 1 && number % 12 != 4 && number % 12 != 9 && number % 12 != 2 && number % 12 != 7) {
                    number++;
                }
                break;
            case 9:
                if (bitMapModule.getMark() != 8 && number % 12 != 1 && number % 12 != 4 && number % 12 != 9 && number % 12 != 2) {
                    number++;
                }
                break;
            case 10:
                if (bitMapModule.getMark() != 8 && number % 12 != 1 && number % 12 != 4 && number % 12 != 9) {
                    number++;
                }
                break;
            case 11:
                if (bitMapModule.getMark() != 8 && number % 12 != 1 && number % 12 != 4) {
                    number++;
                }
                break;

            case 12:
                if (bitMapModule.getMark() != 8 && number % 12 != 1) {
                    number++;
                }
                break;
            case 13:
                if (bitMapModule.getMark() != 8) {
                    number++;
                }
                break;
            default:
                break;
        }
        return number;
    }

    private void drawLine(Canvas canvas, BitMapModule bitMapModule) {
        if (bitMapModule != null && bitMapModule.getNoteType() != 0 && bitMapModule.isDrawLine() && !bitMapModule.isRepose()) {
            RectF rectOld = bitMapModule.getRectF();
            RectF rectF = new RectF();
            rectF.top = rectOld.top;
            rectF.bottom = rectOld.bottom;
            rectF.left = rectOld.left;
            rectF.right = rectOld.right;
            if (courseA5) {
                Rect rect = getBitmapSize(bitMapModule.getBitmap());
                rectF.bottom = bitMapModule.getRectF().bottom * loadSize / 2 - bitMapModule.getRect().bottom * loadSize / 2 / 2 + rect.bottom / 2;
                rectF.top = rectF.bottom - rect.bottom;
                rectF.left = bitMapModule.getRectF().left * loadSize / 2 - bitMapModule.getRect().right * loadSize / 2 / 2 + rect.right / 2;
                rectF.right = rectF.left + rect.right;
                LogUtil.i(TAG, "rectF.bottom=" + rectF.bottom + " rectF.top=" + rectF.top + " rectF.left=" + rectF.left + " rectF.right=" + rectF.right);
            }
            List<CourseDrawLineModule> courseDrawLineModuleList = new ArrayList<>();
            Rect rect = getBitmapSize(note4HeadBitmap);
            float lineLeft = rectF.left;
            float lineRight;
            if (bitMapModule.getNoteType() == 16) {
                lineRight = rectF.right;
            } else {
                lineRight = rectF.left + rect.right;
            }
            if (rectF.bottom < pdfBottom) {
                int position = (int) ((pdfBottom - pdfSpacing * 2 - rectF.bottom + rect.bottom * 2) / pdfSpacing);
                int position1 = (int) ((pdfBottom - pdfSpacing * 2 - rectF.bottom + rect.bottom * 2) % pdfSpacing);
                if (position1 < pdfSpacing / 3) {
                    position -= 1;
                }
                for (int i = 1; i < position; i++) {
                    CourseDrawLineModule courseDrawLineModule = new CourseDrawLineModule();
                    courseDrawLineModule.setStartX((lineLeft - lineWidth / 7 * loadSize));
                    courseDrawLineModule.setStopX((lineRight + lineWidth / 7 * loadSize));
                    courseDrawLineModule.setStartY(pdfBottom - pdfSpacing * 2 - (pdfSpacing) * i);
                    courseDrawLineModule.setStopY(pdfBottom - pdfSpacing * 2 - (pdfSpacing) * i);
                    courseDrawLineModuleList.add(courseDrawLineModule);
                }
            } else {
                int position = (int) ((rectF.bottom - pdfBottom - rect.bottom) / pdfSpacing);
                int position1 = (int) ((rectF.bottom - pdfBottom - rect.bottom) % pdfSpacing);
                if (position1 < pdfSpacing / 3) {
                    position -= 1;
                }
                for (int i = 1; i < position; i++) {
                    CourseDrawLineModule courseDrawLineModule = new CourseDrawLineModule();
                    courseDrawLineModule.setStartX((lineLeft - lineWidth / 7 * loadSize));
                    courseDrawLineModule.setStopX((lineRight + lineWidth / 7 * loadSize));
                    courseDrawLineModule.setStartY(pdfBottom + pdfSpacing * 2 + (pdfSpacing) * i);
                    courseDrawLineModule.setStopY(pdfBottom + pdfSpacing * 2 + (pdfSpacing) * i);
                    courseDrawLineModuleList.add(courseDrawLineModule);
                }
            }
            if (courseDrawLineModuleList.size() > 0) {
                bufferPaint.setStrokeWidth((float) 2.0);
                for (int i = 0; i < courseDrawLineModuleList.size(); i++) {
                    CourseDrawLineModule courseDrawLineModule = courseDrawLineModuleList.get(i);
                    canvas.drawLine(courseDrawLineModule.getStartX(), courseDrawLineModule.getStartY(),
                            courseDrawLineModule.getStopX(), courseDrawLineModule.getStopY(), bufferPaint);
                }
                bufferPaint.setStrokeWidth((float) 1.0);
            }
        }
    }

    private void addLine(int y, BitMapModule bitMapModule) {
        if (bitMapModule.isMeasureLine()) {
            bitMapModule.getRectF().top = y - bitMapModule.getRect().bottom / 2;
            bitMapModule.getRectF().bottom = bitMapModule.getRectF().top + bitMapModule.getRect().bottom;
        } else {
            Rect rect = getBitmapSize(note4HeadBitmap);
            RectF rectF = bitMapModule.getRectF();
            int position;
            int bottom;
            int bottomOver;
            if (courseA5 && y > courseA5Y1 + bitMapModule.getRect().bottom && y < courseA5Y2) {
                if (y > pdfBottom) {
                    position = (y - pdfBottom) / pdfSpacing;
                    bottomOver = (y - pdfBottom) % pdfSpacing;
                    bottom = pdfSpacing * position + pdfBottom;
                } else {
                    position = (pdfBottom - y) / pdfSpacing;
                    bottomOver = (pdfBottom - y) % pdfSpacing;
                    bottom = pdfBottom - pdfSpacing * position;
                }
                LogUtil.i(TAG, "bottomOver=" + bottomOver + " bottom=" + bottom + " y=" + y + " pdfSpacing=" + pdfSpacing);
                if (bottomOver < pdfSpacing / 3) {
                    if (y > pdfBottom) {
                        rectF.bottom = bottom;
                    } else {
                        rectF.bottom = (bottom);
                    }
                } else {
                    if (y > pdfBottom) {
                        rectF.bottom = (bottom + pdfSpacing / 2);
                    } else {
                        rectF.bottom = (bottom - pdfSpacing / 2);
                    }
                }
            }
//            rectF.top = e.getY() - bitMapModuleList.get(bitMapModuleList.size() - 1).getRect().bottom;
            rectF.top = rectF.bottom - bitMapModule.getRect().bottom;
            returnPitch(bitMapModule, rectF, rect);
        }
        invalidate();
    }

    public interface CourseViewListener {
        /**
         * 返回绘制操作
         *
         * @param type 1：临时记号还原
         */
        void courseViewResult(int type);
    }

    private CourseViewListener courseViewListener;

    public void setCourseViewListener(CourseViewListener courseViewListener) {
        this.courseViewListener = courseViewListener;
    }

}
